Understanding Computer Programming

Osher Lifelong Learning Institute
University of Illinois, Urbana-Champaign

Scott Badman, Instructor


Topic: Programming Elements as illustrated by the pseudocode

January 28, 2016


Sequential execution:
    The computer simply does each instruction in the order they are written in the program.

Input and Output:
    Done by the Operating System (Windows, Mac OS X, Android, etc.) on request by a program (we'll see how later).

Variables:
    Human friendly names for locations in the computer's memory where a program can store a number.

    Examples: number divisor intermediate remainder

Arithmetic expressions:
    Variables and numbers combined using ordinary arithmetic operators (+, -, * for multiplication, / for division)
        using parentheses, the same way you did in school.

    Example: intermediate - divisor

Logic expressions:
    Logical expressions can make "True" and "False" decisions by comparing two numbers as "equal",
        "greater than", or "less than", possibly combined with AND, OR, or NOT.

    Example: intermediate >= divisor    (read as "intermediate is greater than or equal to divisor")

Assignment:
    The way a program puts a new value into a variable, replacing the old value.
    Only a variable can be to the left of the assignment symbol (the backarrow, <--, in our pseudocode;
        the equals sign, =, in most computer languages).
    Any number, variable, or arithmetic expression can be to the right of the assignment symbol.
    The value on the right is calculated, and placed into the variable on the left.

    Example: intermediate <-- number

Repetition - WHILE loops:

    A WHILE loop first tests the numeric comparison(s) at the beginning, such as: intermediate >= divisor
    Multiple numeric expressions can be combined with AND, OR, or NOT.
    The result of the numeric comparisons is always either TRUE or FALSE.

    WHILE comparison(s)
        One or more lines of code that is done if the comparison is true.
    END WHILE    The computer automatically jumps back to the beginning of the while loop to test the comparison(s) again.
    In any case, the program continues here after the WHILE loop comparison(s) test false.

Our pseudo-code with the elements specified:

Input number                                 Input/Output of a Variable
Input divisor                                Input/Output of a Variable

intermediate <-- number                      Assignment, copying one variable to another

While intermediate >= divisor                WHILE loop and Logical Expression
    intermediate <-- intermediate - divisor      Assignment of the result of an Arithmetic Expression
End While                                    end of WHILE loop

remainder <-- intermediate                   Assignment

Output remainder                             Input/Output of a Variable



Understanding Computer Programming

Osher Lifelong Learning Institute
University of Illinois, Urbana-Champaign

Scott Badman, Instructor